<?php

namespace Admin\Models\user;

use Admin\Models\BaseModel;
class XhsysServerteacher extends BaseModel
{
    /**
     *
     * @var integer
     */
    public $iSTId;

    /**
     *
     * @var integer
     */
    public $iServerId;

    /**
     *
     * @var string
     */
    public $iTeacherId;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var integer
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHSys_ServerTeacher");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSys_ServerTeacher';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysServerteacher[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysServerteacher
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * @param $serverId
     * @param $teacherId
     * @return bool|XhsysServerteacher
     * 根据服务人员及教师ID获取关系记录，有则返回false，否则新建
     * create by ck 20160726
     */
    public static function getRecord($serverId,$teacherId)
    {
        $obj = self::findFirst("iServerId = '{$serverId}' AND iTeacherId = '{$teacherId}' AND bDelete = 0");
        if($obj) return false;
        $obj = new self;
//        $obj->iSTId      = $obj->getNewId();
        $obj->iServerId  = $serverId;
        $obj->iTeacherId = $teacherId;
        return $obj;
    }

    public function getNewId()
    {
        return $this->getDI()->get('main')->getTableId('XHSys_ServerTeacher');
    }

}
